﻿using TouchSocket.Core;
using TouchSocket.Http;
using TouchSocket.Rpc;
using TouchSocket.Sockets;
using WebAPITest;

var service = new HttpService();
await service.SetupAsync(new TouchSocketConfig()
                        .SetListenIPHosts(7789)
                        .ConfigureContainer(a =>
                         {
                             a.AddConsoleLogger();
                             a.AddRpcStore(store =>
                             {
                                 store.RegisterServer<ApiServer>();//注册服务
                             });
                         })
                        .ConfigurePlugins(a =>
                         {
                             a.UseTcpSessionCheckClear();

                             // 配置Html目录静态文件服务
                             var staticPage = a.UseHttpStaticPage();
                             var htmlPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Html");
                             Directory.CreateDirectory(htmlPath);
                             staticPage.AddFolder(htmlPath.Replace('\\', '/'), "/");

                             a.UseWebApi();

                             //此插件是http的兜底插件，应该最后添加。作用是当所有路由不匹配时返回404.且内部也会处理Option请求。可以更好的处理来自浏览器的跨域探测。
                             a.UseDefaultHttpServicePlugin();
                         }));
await service.StartAsync();
Console.WriteLine("访问: http://localhost:7789/upload.html");
Console.WriteLine("API接口: http://localhost:7789/ApiServer/Upload");

Console.ReadLine();

